<?php

use kzo\base\widgets\ui\common\grid\GridView;
use yii\helpers\Html;
use yii\helpers\Url;
use kzo\base\models\statics\EntityModelStatus;
use kzo\base\models\statics\OperationEvent;
use kzo\base\widgets\ui\common\grid\ActionColumn;

/* @var $this yii\web\View */
/* @var $searchModel common\models\c2\search\LessonApplySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $model common\models\c2\search\LessonApplySearch */

$this->title = Yii::t('app.c2', 'Lesson Applies');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="lesson-apply-index">

    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,

        'pjax' => true,
        'hover' => true,
        'showPageSummary' => true,
        'panel' => ['type' => GridView::TYPE_SUCCESS, 'heading' => Yii::t('app.c2', 'Items')],
        'toolbar' => [
            [
                'content' =>
                    Html::a('<i class="fas fa-plus"></i>', ['edit'], [
                        'class' => 'btn btn-success',
                        'title' => Yii::t('app.c2', 'Add'),
                        'data-pjax' => '0',
                    ]) . ' ' .
                    // Html::button('<i class="fas fa-minus"></i>', [
                    //     'class' => 'btn btn-danger',
                    //     'title' => Yii::t('app.c2', 'Delete Selected Items'),
                    //     'onClick' => "jQuery(this).trigger('" . OperationEvent::DELETE_BY_IDS . "', {url:'" . Url::toRoute('multiple-delete') . "'});",
                    // ]) . ' ' .
                    Html::a('<i class="fas fa-redo"></i>', Url::current(), [
                        'class' => 'btn btn-outline-secondary',
                        'title' => Yii::t('app.c2', 'Reset Grid')
                    ]),
                'options' => ['class' => 'btn-group mr-2']
            ],
            '{export}',
            '{toggleData}',
        ],
        'exportContainer' => ['class' => 'btn-group mr-2'],
        'exportConfig' => [],
        'columns' => [
            ['class' => 'kartik\grid\CheckboxColumn'],
            ['class' => 'kartik\grid\SerialColumn'],
            [
                'class' => 'kartik\grid\ExpandRowColumn',
                'value' => function ($model, $key, $index, $column) {
                    return GridView::ROW_COLLAPSED;
                },
                'detail' => function ($model, $key, $index, $column) {
                    return Yii::$app->controller->renderPartial('_detail', ['model' => $model]);
                },
            ],
            [

                'attribute' => 'lesson_daily_id',
                'width' => '100px',
                'value' => function ($model) {
                    return !is_null($model->lessonDaily) ? $model->lessonDaily->lesson->name : '';
                }
            ],
            [

                'label' => Yii::t('app.c2', 'Lesson Date'),
                'value' => function ($model) {
                    $ld = $model->lessonDaily;
                    return !is_null($ld) ? date("Y-m-d", strtotime($ld->lesson_at)) . "(" . $ld->lesson_daytime . ")" : '';
                }
            ],
            [

                // 'attribute' => 'user_id',
                'label' => Yii::t('app.c2', 'Apply Username'),
                'value' => function ($model) {
                    return $model->user->username;
                }
            ],
            [

                // 'attribute' => 'card_hold_id',
                'label' => Yii::t('app.c2', 'Used Card'),
                'value' => function ($model) {
                    return $model->cardHold->card->name;
                }
            ],
            [

                'label' => Yii::t('app.c2', 'Expired Time'),
                'value' => function ($model) {
                    return $model->cardHold->expired_at;
                }
            ],
            [

                'label' => Yii::t('app.c2', 'Remain Time'),
                'value' => function ($model) {
                    return $model->cardHold->remain_time;
                }
            ],
            // 'status',
            [
                'attribute' => 'created_at',
                'label' => Yii::t('app.c2', 'Apply Time')
            ],
            // 'updated_at',
            [
                'attribute' => 'status',
                'class' => '\kartik\grid\EditableColumn',
                'editableOptions' => [
                    'inputType' => \kartik\editable\Editable::INPUT_DROPDOWN_LIST,
                    'formOptions' => ['action' => Url::toRoute('editColumn')],
                    'data' => EntityModelStatus::getHashMap('id', 'label'),
                    'displayValueConfig' => EntityModelStatus::getHashMap('id', 'label'),
                ],
                'filter' => EntityModelStatus::getHashMap('id', 'label'),
                'value' => function ($model) {
                    return $model->getStatusLabel();
                }
            ],
            // [
            //     'class' => ActionColumn::className(),
            //     'width' => '150px',
            //     'buttons' => [
            //         'update' => function ($url, $model, $key) {
            //             return Html::a('<span class="fas fa-pencil-alt"></span>', ['edit', 'id' => $model->id], [
            //                 'title' => Yii::t('app', 'Info'),
            //                 'data-pjax' => '0',
            //             ]);
            //         }
            //     ]
            // ],

        ],
    ]); ?>

</div>
